package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.MessageActivityModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/24.
 */

public class MessageActivityAdapter extends BaseAdapter {

    private Context mContext;
    List<MessageActivityModel> model= new ArrayList<>();
    public MessageActivityAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return model.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<MessageActivityModel> model){

        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.itme_message, null);
            holder.item_image = (ImageView) convertView
                    .findViewById(R.id.item_image);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);
            holder.item_content = (TextView) convertView
                    .findViewById(R.id.item_content);
            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        System.out.println("stringmd5"+model.size());
        MessageActivityModel model1 = model.get(position);
        if (model1.getMsgstatus().equals("2")){
            holder.item_image.setImageResource(R.mipmap.message1);
        }else {
            holder.item_image.setImageResource(R.mipmap.message2);
        }
        holder.item_title.setText(model1.getMsgtitle());
        holder.item_content.setText(model1.getMsgcontent());
        if (!Sundry.getStinges(model1.getAddtime())){
            holder.item_time.setText(Sundry.getStrsTime(model1.getAddtime()));
        }
        return convertView;
    }

    class ViewHolder {
        ImageView item_image;
        TextView item_title;
        TextView item_content;
        TextView item_time;
    }
}

